﻿using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Interactivity;
using NewUI.ViewModels;
using Printer;

namespace NewUI.Views;

public partial class PrinterLabel : UserControl
{
    private FileSystemWatcher _imageWatcher;
    private string _imageDirectory;
    
    public PrinterLabel()
    {
        InitializeComponent();
        DataContext = new PrinterViewModel();
    }
    
    private void OnOpenPngClick(object sender, RoutedEventArgs e)
    {
        try
        {
            string path = GetExeDirectory() + "PrinterTemplate.exe";
            Process.Start(path);
        }
        catch (Exception ex)
        {
            Debug.WriteLine($"打开程序失败: {ex.Message}");
        }
    }
    
    private string? GetExeDirectory()
    {
        string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\BtwTemplates\\Runner\\";
        if (Directory.Exists(path))
        {
            return path;
        }
        return null;
    }
    
}